namespace ColumnOrderingSetup.Features.SiteLevel
{
    using System;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;

    using com.savealot.Extensions.SharePointExtensions;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Security;

    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>
    [Guid( "04a5ae01-6336-487c-9183-a47a8b025d41" )]
    public class SiteLevelEventReceiver : SPFeatureReceiver
    {
        #region Fields

        const string FEATURE = "com.savealot.ColumnOrderingSetup.SITELEVEL";

        #endregion Fields

        #region Methods

        // Uncomment the method below to handle the event raised after a feature has been activated.
        public override void FeatureActivated( SPFeatureReceiverProperties properties )
        {
            try
            {
                if ( !( properties.Feature.Parent is SPSite ) )
                {
                    throw new Exception( string.Format( "{0} :: Error activating feature. Feature parent is not of type SPSite.", FEATURE ) );
                }
            }
            catch ( Exception e )
            {
                throw new Exception( string.Format( "Error occurred in {0} FeatureActivated. {1} {2}", FEATURE, e.Message, e.StackTrace ), e );
            }
        }

        // Uncomment the method below to handle the event raised before a feature is deactivated.
        public override void FeatureDeactivating( SPFeatureReceiverProperties properties )
        {
            try
            {
                if ( !( properties.Feature.Parent is SPSite ) )
                {
                    return;
                }
            }
            catch ( Exception e )
            {
                throw new Exception( string.Format( "Error occurred in {0} FeatureDeactivating. {1} {2}", FEATURE, e.Message, e.StackTrace ), e );
            }
        }

        #endregion Methods
    }
}